package top.kaoshanji.p1ch01c;

import top.kaoshanji.p1ch01c.exception.BaseException;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * 代码清单 p1ch01c-03：抛出try语句块中产生的原始异常第1种方法(1.4.3节)
 * 实现自己的异常类
 * author kaoshanji
 * ^_^
 * create time 2024/12/22 19:24
 */
public class ReadFileV1 {

    public void read(String fileName) throws BaseException {

        FileInputStream input = null;
        IOException readException = null;

        try {
            input = new FileInputStream(fileName);
        } catch (IOException ex) {
            readException = ex;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException ex) {
                    if (readException == null) {
                        readException = ex;
                    }
                }
            }

            if (readException != null) {
                throw new BaseException(readException);
            }

        }


    }



}
